<?php

namespace App\Lib;

class ApiResponse
{
    const CODE_SUCCESS = 200;
    const CODE_FAIL = -100;
    const CODE_AUTH_FAIL = -101;

    static function success($data = [],$status=self::CODE_SUCCESS)
    {
        return self::returnArray($status, $data,'操作成功');
    }

    static function fail($message, $status = self::CODE_FAIL, $data = [])
    {
        return self::returnArray($status, $data, $message);
    }

    static function returnArray($status, $data, $message)
    {
        return ['status' => $status, 'data' => $data, 'message' => $message];
    }

    static function returnJson($status, $data, $message)
    {
        return response()->json(self::returnArray($status, $data, $message));
    }

    static function successJson($data = [])
    {
        return self::returnJson(self::CODE_SUCCESS, $data, '操作成功');
    }

    static function failJson($message, $status = self::CODE_FAIL, $data = [])
    {
        return self::returnJson($status, $data, $message);
    }

}
